package com.hualan.mapper;

import com.hualan.pojo.ConsultantLevels;
import com.hualan.pojo.Consultants;
import com.hualan.pojo.Zixunleibie;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ZixunyuyueMapper {

    @Insert("insert into zixunyuyue(uid,tid,level,zixunleibie,time,neirong) values (#{uid},#{tid},#{level},#{zixunleibie},#{time},#{neirong})")
    Integer addzixun(@Param("uid") Integer uid, @Param("tid") Integer tid, @Param("level") String level, @Param("zixunleibie") String zixunleibie, @Param("time") String time, @Param("neirong") String neirong);







    @Select(value = "select consultants.* from consultants join consultant_levels on consultants.level_id=consultant_levels.id and consultant_levels.level_name = #{level} join zixunleibie join zixunleibie_consultant on zixunleibie.id=zixunleibie_consultant.zixun_id and zixunleibie_consultant.consultants_id=consultants.id and zixunleibie.neirong=#{selected} where consultants.del=0")
    @Results({
            @Result(property = "id",column = "id",id = true),
            @Result(
                    property = "consultantLevels",
                    column = "level_id",
                    one = @One(select = "findById")),
            @Result(
                    property = "zixunleibieList",
                    column = "id",
                    many = @Many(select = "findByIdHuifu"))
    })
    List<Consultants> listAll(@Param("level") String level,@Param("selected") String selected);

    @Select("select level_name from consultant_levels where consultant_levels.del=0 and id = #{id}")
    ConsultantLevels findById(Integer id);

    @Select("select zixunleibie.* from zixunleibie join zixunleibie_consultant on zixunleibie.del=0 and zixunleibie_consultant.zixun_id=zixunleibie.id where zixunleibie_consultant.consultants_id = #{id}")
    Zixunleibie findByIdHuifu(Integer id);

    @Insert("insert into zixunyuyue(uid,tid,level,zixunleibie,time,neirong) values (#{uid},#{tid},#{level},#{zixunleibie},#{time},#{neirong})")
    Integer addshouye(@Param("uid") Integer uid, @Param("tid") Integer tid, @Param("level") String level, @Param("zixunleibie") String zixunleibie, @Param("time") String time, @Param("neirong") String neirong);




}
